package com.feilong.edgeAI.adapter;

import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import com.aiibt.common.core.WDRecyclerAdapter;
import com.blankj.utilcode.util.ScreenUtils;
import com.feilong.edgeAI.R;
//import com.feilong.edgeAI.databinding.HomeClassifyLayoutBindingImpl;
import com.feilong.edgeAI.databinding.HomeCommandItemBinding;
import com.feilong.edgeAI.model.CommadClassify;
import com.feilong.edgeAI.model.Commands;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

public class CommadsAdapter extends WDRecyclerAdapter<Commands> {
    private int width;
    private int index;
    public CommadsAdapter(List<Commands> datas ,int index) {
        this.index = index;
        width = (int) (ScreenUtils.getScreenWidth()/2.2);
        addAll(datas);
    }
    private int bgs[] = {R.drawable.command_bg1,R.drawable.command_bg2,R.drawable.command_bg3,R.drawable.command_bg4,R.drawable.command_bg5,R.drawable.command_bg6,R.drawable.command_bg7,R.drawable.command_bg8,R.drawable.command_bg9,R.drawable.command_bg10,R.drawable.command_bg11,R.drawable.command_bg12};
    @Override
    protected int getLayoutId() {
        return R.layout.home_command_item;
    }

    @Override
    protected void bindView(ViewDataBinding binding, Commands item, int position) {
        HomeCommandItemBinding b = (HomeCommandItemBinding) binding;
        b.commandView.setText("\""+item.getCommand()+"\"");
        if(0==index){
            int pos = position%bgs.length;
            b.commandView.setBackgroundResource(bgs[pos]);

            b.commandView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    EventBus.getDefault().post(item);
                }
            });
        }else{
            b.commandView.setBackgroundResource(R.drawable.shape_bg_rect_gray);
        }
//        Log.d("bindView", "bindView: "+);
//        b.title.setText(item.getTitle());

     /*   b.bookCover.setLayoutParams(params);
        b.bookName.setText(item.getCatalog_name());
        b.bookCover.setImageURI(Uri.parse(baseUrl+item.getCatalog_image()));
        b.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null!=onItemClickListener){
                    onItemClickListener.onItemClick(item);
                }
            }
        });*/
    }

    static class ImageHolder extends RecyclerView.ViewHolder {

        public ImageHolder(@NonNull View view) {
            super(view);
        }
    }
    public interface OnItemClickListener<T>{
        void onItemClick(T item);
    }
    private OnItemClickListener onItemClickListener;
    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }
}
